﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace ERPTOOLS.Class
{
    public class DoCheck
    {
        public static DataTable CheckGYS(string sql, string sql1)
        {
            DataTable dt=new DataTable();
            int seq = 0;
            bool find = false;
            dt.Columns.Add("序号");
            dt.Columns.Add("供应商全称");
            dt.Columns.Add("企业编号");
            dt.Columns.Add("供应商编号");
            dt.Columns.Add("异常描述");
            DataTable dt1 = DBLink.LinkERP(sql, "ERPGYS");
            DataTable dt2 = DBLink.LinkSCM(sql1, "SCMGYS");
            foreach (DataRow row in dt1.Rows)
            {
                find = false;
                foreach (DataRow row1 in dt2.Rows)
                {
                    if (row["GYSQC"].Equals(row1["GYSQC"]))
                    {
                        find = true;
                        if (row["GYSBH"].Equals(row1["GYSBH"]))
                        {

                        }
                        else
                        {
                            dt.Rows.Add();
                            dt.Rows[seq]["序号"] = seq + 1;
                            dt.Rows[seq]["供应商全称"] = row["GYSQC"];
                            dt.Rows[seq]["企业编号"] = row1["QYBH"];
                            dt.Rows[seq]["供应商编号"] = row["GYSBH"];
                            dt.Rows[seq]["异常描述"] = "错误： ERP中供应商编号为" + row["GYSBH"] + "  但OpenSCM平台的ERP供应商编号为" + row1["GYSBH"];
                            seq++;
                        }
                    }
                }
                if (!find)
                {
                    dt.Rows.Add();
                    dt.Rows[seq]["序号"] = seq + 1;
                    dt.Rows[seq]["供应商全称"] = row["GYSQC"];
                    dt.Rows[seq]["企业编号"] = "";
                    dt.Rows[seq]["供应商编号"] = row["GYSBH"];
                    dt.Rows[seq]["异常描述"] = "错误： ERP中有此供应商但 OpenSCM 平台无此供应商";
                    seq++;
                }
            }
            foreach (DataRow row in dt2.Rows)
            {
                find = false;
                foreach (DataRow row1 in dt1.Rows)
                {
                    if (row["GYSQC"].Equals(row1["GYSQC"]))
                    {
                        find = true;
                    }
                }
                if (!find)
                {
                    dt.Rows.Add();
                    dt.Rows[seq]["序号"] = seq + 1;
                    dt.Rows[seq]["供应商全称"] = row["GYSQC"];
                    dt.Rows[seq]["企业编号"] = "";
                    dt.Rows[seq]["供应商编号"] = row["GYSBH"];
                    dt.Rows[seq]["异常描述"] = "警告: OpenSCM 平台有此供应商但ERP中无此供应商";
                    seq++;
                }
            }
            return dt;
        }

        public static DataTable CheckKH(string sql, string sql1)
        {
            DataTable dt = new DataTable();
            int seq = 0;
            bool find = false;
            dt.Columns.Add("序号");
            dt.Columns.Add("客户全称");
            dt.Columns.Add("企业编号");
            dt.Columns.Add("客户编号");
            dt.Columns.Add("异常描述");
            DataTable dt1 = DBLink.LinkERP(sql, "ERPKH");
            DataTable dt2 = DBLink.LinkSCM(sql1, "SCMKH");
            foreach (DataRow row in dt1.Rows)
            {
                find = false;
                foreach (DataRow row1 in dt2.Rows)
                {
                    if (row["KHQC"].Equals(row1["KHQC"]))
                    {
                        find = true;
                        if (row["KHBH"].Equals(row1["KHBH"]))
                        {

                        }
                        else
                        {
                            dt.Rows.Add();
                            dt.Rows[seq]["序号"] = seq + 1;
                            dt.Rows[seq]["客户全称"] = row["KHQC"];
                            dt.Rows[seq]["企业编号"] = row1["QYBH"];
                            dt.Rows[seq]["客户编号"] = row["KHBH"];
                            dt.Rows[seq]["异常描述"] = "错误： ERP中客户编号为" + row["KHBH"] + "  但OpenSCM平台的ERP客户编号为" + row1["KHBH"];
                            seq++;
                        }
                    }
                }
                if (!find)
                {
                    dt.Rows.Add();
                    dt.Rows[seq]["序号"] = seq + 1;
                    dt.Rows[seq]["客户全称"] = row["KHQC"];
                    dt.Rows[seq]["企业编号"] = "";
                    dt.Rows[seq]["客户编号"] = row["KHBH"];
                    dt.Rows[seq]["异常描述"] = "错误： ERP中有此客户但 OpenSCM 平台无此客户";
                    seq++;
                }
            }
            foreach (DataRow row in dt2.Rows)
            {
                find = false;
                foreach (DataRow row1 in dt1.Rows)
                {
                    if (row["KHQC"].Equals(row1["KHQC"]))
                    {
                        find = true;
                    }
                }
                if (!find)
                {
                    dt.Rows.Add();
                    dt.Rows[seq]["序号"] = seq + 1;
                    dt.Rows[seq]["客户全称"] = row["KHQC"];
                    dt.Rows[seq]["企业编号"] = "";
                    dt.Rows[seq]["客户编号"] = row["KHBH"];
                    dt.Rows[seq]["异常描述"] = "警告: OpenSCM 平台有此客户但ERP中无此客户";
                    seq++;
                }
            }
            return dt;
        }

    }
}
